package org.jeecg.modules.module.schedule;

import com.alibaba.fastjson.JSONObject;
import com.xkcoding.http.HttpUtil;
import org.jeecg.modules.module.constant.UrlConstant;
import org.jeecg.modules.module.mapper.StockMapper;
import org.jeecg.modules.module.model.Stock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Component
public class ScheduleTest {

    @Value("${byapi.licence}")
    private String licence;

    @Resource
    private StockMapper stockMapper;

//    @Scheduled(cron = "0 0/1 * * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void pullData(){
        String stockListStr = HttpUtil.get(UrlConstant.STOCK_LIST_URL + licence);
        List<Stock> stockList = JSONObject.parseArray(stockListStr, Stock.class);
        stockMapper.saveOrUpdateBatch(stockList);
    }

}
